package com.myblog.mapper;

import com.myblog.model.Visitor;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface VisitorMapper {
    @Select("select visitorNum from visitor where pageName = 'totalVisitor'")
    long selectTotalVisitorNum();

    @Select("select * from visitor where pageName = 'totalVisitor'")
    Visitor selectTotalVisitor();

    @Select("select * from visitor where pageName = 'visitorVolume'")
    Visitor selectVolumeVisitorNum();

    @Insert("insert into visitor(visitorNum,pageName) values (#{visitorNum},#{pageName})")
    void insertVisitor(@Param(value = "visitorNum")long visitorNum,@Param(value = "pageName")String pageName);

    Visitor selectVisitorNumByPageName(String pageName);

    void updateVisitorByPageName(@Param(value = "visitorNum") long visitorNum, @Param(value = "pageName") String pageName);

    //通过其他数据获取总访问量
    @Select("select sum(visitorNum) from visitor where pageName != 'totalVisitor'")
    Integer selectTotalVisitorNumByOthers();
}
